package com.atguigu.eduservice.controller;


import com.atguigu.common.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.coursevo.CourseInfoForm;
import com.atguigu.eduservice.entity.coursevo.CoursePublishVo;
import com.atguigu.eduservice.service.EduCourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-04-13
 */
@RestController
@RequestMapping("/eduservice/course")
@Api(description="发布课程 不可用")
@CrossOrigin
public class EduCourseController {

    @Autowired
    private EduCourseService courseService;

    //添加课程基本信息
    @PostMapping("addCourseBseInfo")
    @ApiOperation(value = "添加课程基本信息")
    public R addCourseBseInfo(@RequestBody CourseInfoForm courseInfoForm) {
        //返回添加之后课程id
        String courseId = courseService.addCourseInfo(courseInfoForm);
        return R.ok().data("courseId",courseId);
    }

    //根据课程id查询课程信息
    @GetMapping("getCourseInfo/{id}")
    @ApiOperation(value = "根据课程id查询课程信息")
    public R getCourseInfo(@PathVariable String id) {
        CourseInfoForm courseInfoForm = courseService.getCourseInfo(id);
        return R.ok().data("courseInfo",courseInfoForm);
    }

    //修改课程信息
    @PostMapping("updateCourseInfo")
    @ApiOperation(value = "修改课程信息")
    public R updateCourseInfo(@RequestBody CourseInfoForm courseInfoForm) {
        courseService.updateCourse(courseInfoForm);
        return R.ok();
    }

    //根据课程id查询课程确认信息
    @GetMapping("getCourseConfirmInfo/{id}")
    @ApiOperation(value = "根据课程id查询课程确认信息")
    public R getCourseConfirmInfo(@PathVariable String id) {
        CoursePublishVo coursePublishVo = courseService.getPublishCourse(id);
        return R.ok().data("publishInfo",coursePublishVo);
    }

    //课程最终发布
    @PutMapping("publishCourse/{id}")
    @ApiOperation(value = "课程最终发布")
    public R publishCourse(@PathVariable String id) {
        EduCourse eduCourse = new EduCourse();
        eduCourse.setId(id);
        eduCourse.setStatus("Normal");
        courseService.updateById(eduCourse);
        return R.ok();
    }

    //课程列表
    //TODO 实现简单查询，完善条件查询带分页，参考讲师列表
    @GetMapping("getCourseList")
    @ApiOperation(value = "课程列表")
    public R getCourseList() {
        List<EduCourse> list = courseService.list(null);
        return R.ok().data("items",list);
    }

    //删除课程接口
    @DeleteMapping("{courseId}")
    @ApiOperation(value = "删除课程接口")
    public R deleteCourse(@PathVariable String courseId) {
        courseService.deleteCourse(courseId);
        return R.ok();
    }
}

